def dede(zov):
    kede = 0
    for j in range(2,zov):
        if zov%j == 0:
            kede += 1
            break
    if kede == 0:
        return zov
    else:
        return 0
    
print("Введите 3 слова через пробел:")
cifri = list(map(str,input().split()))
nichego = ""
vi=["zero","one","two","three","four","five","six","seven","eight","nine"]
for i in range(len(cifri)):
    for j in range(len(vi)):
        if cifri[i] == vi[j]:
            nichego+=str(j)
zavp=10000000000
if len(nichego)!=3:
    print("Wrong input")
elif int(nichego)== dede(int(nichego)):
    print(nichego)
else:
    nichego = int(nichego)
    for i in range(nichego - 50, nichego + 50):
        if (dede(int(i)) != 0) and (zavp > abs(nichego - i)):
            pr = i
            zavp = abs(nichego - i)
    print(pr)
